home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / Snippets / Toolbox / ProgressBars 1.0 / Sources / Events.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-17  |  2.7 KB  |  179 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        Events.c
  3.  
  4.     Contains:    Main event loop and basic keyboard/mouse processing
  5.  
  6.     Written by:    Chris White, Developer Technical Support
  7.     
  8.     Copyright:    © 1996 by Apple Computer, Inc., all rights reserved.
  9.     
  10.     Change History (most recent first):
  11.     
  12.             1/22/96            CW        First release
  13.  
  14. */
  15.  
  16.  
  17. #pragma segment Core
  18.  
  19.  
  20. // System Includes
  21.  
  22. #ifndef __MEMORY__
  23.     #include <Memory.h>
  24. #endif
  25.  
  26. #ifndef __APPLEEVENTS__
  27.     #include <AppleEvents.h>
  28. #endif
  29.  
  30. #ifndef __DIALOGS__
  31.     #include <Dialogs.h>
  32. #endif
  33.  
  34. #ifndef __DESK__
  35.     #include <Desk.h>
  36. #endif
  37.  
  38. #ifndef __WINDOWS__
  39.     #include <Windows.h>
  40. #endif
  41.  
  42.  
  43.  
  44.  
  45. // Application includes
  46.  
  47. #ifndef __BAREBONES__
  48.     #include "BareBones.h"
  49. #endif
  50.  
  51. #ifndef __PROTOTYPES__
  52.     #include "Prototypes.h"
  53. #endif
  54.  
  55.  
  56.  
  57.  
  58. // static includes
  59.  
  60. static void DoMouseDown ( EventRecord* theEvent );
  61. static void DoKey ( EventRecord*theEvent );
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68. void EventLoop ( void )
  69. {
  70.     OSErr            theErr;
  71.     EventRecord        theEvent;
  72.     
  73.     
  74.     while ( !gQuit )
  75.     {
  76.         WaitNextEvent ( everyEvent, &theEvent, gSleepTime, nil );    
  77.         
  78.         switch ( theEvent.what )
  79.         {
  80.             case mouseDown: 
  81.                 DoMouseDown ( &theEvent );
  82.             break;
  83.             
  84.             case keyDown:
  85.             case autoKey: 
  86.                 DoKey ( &theEvent );
  87.             break;
  88.             
  89.             case activateEvt: 
  90.                 DoActivate ( &theEvent );
  91.             break;
  92.             
  93.             case updateEvt:
  94.                 DoUpdate ( &theEvent );
  95.             break;
  96.             
  97.             case osEvt:
  98.                 if ( (theEvent.message >> 24) & suspendResumeMessage )    // suspend or resume
  99.                 {
  100.                     // Modify the event record to look like an activate/deactivate event
  101.                     theEvent.modifiers = theEvent.message;        // Copy suspend/resume flag
  102.                     theEvent.message = (long) FrontWindow ( );    
  103.                     DoActivate ( &theEvent );
  104.                 }
  105.             break;
  106.             
  107.             case kHighLevelEvent:
  108.                 theErr = AEProcessAppleEvent ( &theEvent );
  109.             break;
  110.         }
  111.         
  112.         AdjustMenus ( );
  113.         
  114.         if ( gHasThreadManager )
  115.             YieldToAnyThread ( );
  116.     }
  117.     
  118.     return;
  119.     
  120. } // EventLoop
  121.  
  122.  
  123.  
  124. static void DoMouseDown ( EventRecord* theEvent )
  125. {
  126.     Point            globalPt = theEvent->where;
  127.     SInt16            windowPart;
  128.     WindowRef        theWindow;
  129.     long            theMenu;
  130.     
  131.     
  132.     windowPart = FindWindow ( globalPt, &theWindow );
  133.     switch ( windowPart )
  134.     {
  135.         case inMenuBar: 
  136.             theMenu = MenuSelect ( globalPt );
  137.             MenuDispatch ( theMenu );
  138.         break;
  139.         
  140.         case inSysWindow:
  141.             // The SystemClick toolbox routine handles system events
  142.             SystemClick ( theEvent, theWindow );
  143.         break;
  144.         
  145.         case inGoAway:
  146.         break;
  147.         
  148.         case inDrag:
  149.             DoDragWindow ( theWindow, theEvent );
  150.         break;
  151.         
  152.         case inContent:
  153.             DoContentClick ( theWindow, theEvent );
  154.         break;
  155.     }
  156.     
  157.     return;
  158.     
  159. } // DoMouseDown
  160.  
  161.  
  162.  
  163. static void DoKey ( EventRecord* theEvent )
  164. {
  165.     char keyPressed = (theEvent->message & charCodeMask);
  166.     
  167.     
  168.     // Command keys get handled by the menu handling routines
  169.     if ( theEvent->modifiers & cmdKey )
  170.         MenuDispatch ( MenuKey ( keyPressed ) );
  171.     
  172.     return;
  173.     
  174. } // DoKey
  175.  
  176.  
  177.  
  178.  
  179.